import React from 'react'
import { HashRouter, Routes, Route, Navigate } from 'react-router-dom'
const Home = React.lazy(() => import('./pages/nav/index'))
import { routes } from './common/routes'
import Login from './pages/login/login'
import NotFound from './NotFound'

export default function App() {
  //处理路由
  function renderRoutes(routes:any) {
    return routes.map((item:any) => {
      return <Route key={item.path} path={item.path} element={item.element} />
    })
  }
  return (
    <React.Suspense>
    <HashRouter>
      <Routes>
        <Route path='/nav' element={<Home/>}>
            {
              renderRoutes(routes)
          }
        </Route>
        <Route path='/login' element={ <Login/>} />
        <Route path='/' element={<Navigate to={"/login"} />} />
        <Route path='*' element={<NotFound />} />
        
      </Routes>
      </HashRouter>
      </React.Suspense>
  )
}
